package com.zjx.springcloud.service.impl;

import com.zjx.springcloud.dao.DeptDao;
import com.zjx.springcloud.entities.Dept;
import com.zjx.springcloud.redis.RedisUtil;
import com.zjx.springcloud.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import javax.annotation.Resource;
import java.util.List;
@Service
@Transactional(rollbackFor=Exception.class,propagation= Propagation.REQUIRES_NEW)
public class DeptServiceImpl implements DeptService {
    @Resource
    private DeptDao deptDao;
    @Resource
    private RedisUtil redisUtil;

    //缓存查询
    @Cacheable(value = "deptQueryDeptAll")
    @Override
    public List<Dept> queryDeptAll() {
//        try {
//
//        }catch (Exception e){
//            e.printStackTrace();
//            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
//        }

        redisUtil.set("ss","ss",10);
        return deptDao.queryDeptAll();
    }



    @Override
    public Integer addDept(Dept dept) {
       int in=deptDao.add(dept);
     System.out.println("***********in:"+dept.getDeptNo());

        return deptDao.add(dept);
    }



}
